#include "kemultilabel.h"

#include <QTimer>
#include <QFont>
#include <QRectF>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QEvent>
#include <QMouseEvent>

#include "css4kepop.h"


KeMultiLabel::KeMultiLabel(QWidget *parent,const QStringList &vs)
    : QWidget{parent}
{
    setAttribute(Qt::WA_TranslucentBackground);
    setWindowFlags(Qt::Popup);//windowFlags() | Qt::FramelessWindowHint |

    setStyleSheet(DefaultQSS_KeLabel);


    auto layout = new QHBoxLayout(this);

    layout->setDirection(QBoxLayout::TopToBottom);
    layout->setSpacing(0);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setAlignment(Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop);

    for(auto &txt:vs)
    {
        QLabel*   _label = new QLabel(txt,this);
        layout->addWidget(_label);
    }
    setLayout(layout);
}

KeMultiLabel::~KeMultiLabel()
{

}

void KeMultiLabel::showAt(int msec,const QPoint &point)
{
    show();
    move(point);
    // No such slot QLabel::timeoutClose(),.h-file add Q_OBJECT, no works
    // QTimer::singleShot(msec,this,SLOT(KeMultiLabel::timeoutClose()));

    QTimer::singleShot(msec,this,&KeMultiLabel::timeoutClose);
}

void KeMultiLabel::mousePressEvent(QMouseEvent *)
{
    // setAttribute(Qt::WA_NoMouseReplay);
    setVisible(false);

}

void KeMultiLabel::timeoutClose()
{
    deleteLater();
}
